package com.zzjson.io.nio.buffer;

import java.nio.ByteBuffer;

/**
 * <p>****************************************************************************</p>
 * <p><b>Copyright © 2010-2019 shuncom team All Rights Reserved<b></p>
 * <ul style="margin:15px;">
 * <li>Description : cn.zzjson.io.nio.buffer</li>
 * <li>Version     : 1.0.0</li>
 * <li>Creation    : 2019年03月26日</li>
 * <li>@author     : zzy0_0</li>
 * </ul>
 * <p>****************************************************************************</p>
 */
public class BufferSlice {
	public static void main(String[] args) {
		ByteBuffer allocate = ByteBuffer.allocate(10);
		for (int i = 0; i < allocate.capacity(); i++) {
			allocate.put((byte) i);
		}
		//创建子缓冲区
		allocate.position(3);
		allocate.limit(7);

		ByteBuffer slice = allocate.slice();
		for (int i = 0; i < slice.capacity(); i++) {
			byte b = slice.get(i);
			b *= 10;
			slice.put(i, b);
		}


		allocate.position(0);
		allocate.limit(allocate.capacity());

		while (allocate.remaining() > 0) {
			System.out.println(allocate.get());
		}
	}
}
